/**
* Graphic Asset-
* Wrapper for the "Image" class in SFML, gives it a string identifier
*
* @date 2011-04-11
* @author Rachel J. Morris
*
* http://www.moosader.com/
* http://code.google.com/p/unicorn-princess/
* GNU GPL v3 license
*/

#ifndef _GraphicAsset
#define _GraphicAsset

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <string>

struct GraphicAsset
{
    sf::Image image;
    std::string name;

    bool Load( std::string filename )
    {
        name = CreateName( filename );
        cout<<"Loading "<<filename<<" as asset "<<name<<endl;
        return image.LoadFromFile( filename );
    }

    std::string CreateName( std::string filename )
    {
        std::string buffer = "";
        for ( int i=0; i<filename.length(); i++ )
        {
            if ( filename[i] == '/' )
            {
                // Dump the buffer, this is a folder.
                buffer = "";
            }
            else if ( filename[i] == '.' )
            {
                return buffer;
            }
            else
            {
                buffer += filename[i];
            }
        }

        return buffer;
    }
};

#endif
